// MayBe函子

class MayBe {
  static of (value) {
    return new MayBe(value)
  }

  constructor(value) {
    this._value = value
  }

  map(fn) {
    return this.ifNothing(this._value) ? MayBe.of(null) : MayBe.of(fn(this._value))
  }

  ifNothing(value) {
    return value === null || value === undefined
  }
}

let r = MayBe.of(undefined)
          .map(x => x.toUpperCase())

console.log(r)